<template>
    <div>

        <el-input v-model="querydolist.workNamedo" style="width: 200px" placeholder="请输入作业名"></el-input>
        <el-button @click="getDoList()" type="primary">查询</el-button>

        <el-table
                :data="DoHomeworkData"
                style="width: 100%">
            <el-table-column
                    prop="workStudo"
                    label="学生姓名"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="workNamedo"
                    label="作业名">
            </el-table-column>
            <el-table-column
                    prop="workContentdo"
                    label="作业详情">
            </el-table-column>
            <el-table-column
                    prop="workAskdo"
                    label="作业要求">
            </el-table-column>
            <el-table-column
                    prop="workTeacherdo"
                    label="作业布置老师">
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            @click="handleEdit(scope.row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="this.querydolist.page"
                :page-sizes="[5, 10, 20, 30]"
                :page-size="this.querydolist.size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="this.total">
        </el-pagination>


        <el-dialog title="用户详情" :visible.sync="dialogFormVisible">
            <el-form :model="dohomeworkform">
                <el-form-item label="学生姓名" >
                    <el-input v-model="dohomeworkform.workStudo" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="作业名" >
                    <el-input v-model="dohomeworkform.workNamedo" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="作业详情" >
                    <el-input v-model="dohomeworkform.workContentdo" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="作业要求" >
                    <el-input v-model="dohomeworkform.workAskdo" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="作业布置老师" >
                    <el-input v-model="dohomeworkform.workTeacherdo" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitForm()">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>
    export default {
        name: "DoHomework",
        data() {
            return {
                DoHomeworkData: [],
                total:0,
                querydolist: {
                    page:1,
                    size:5,
                    workNamedo:"",
                },
                dialogFormVisible: false,
                dohomeworkform: {
                    did:'',
                    workNamedo:"",
                    workStudo:'',
                    workTeacherdo:'',
                    workContentdo:'',
                    workAskdo:''
                },
            }
        },
        mounted() {
            this.getDoList();
        },
        methods:{
            getDoList(){
                this.axios.get('http://localhost:3312/homework/getDoHomeWorkList',{
                    params:{
                        page:this.querydolist.page,
                        size:this.querydolist.size,
                        workNamedo:this.querydolist.workNamedo,
                    }
                }).then((resp)=>{
                    this.DoHomeworkData = resp.data.content.list;
                    this.total = resp.data.content.total;
                })
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.querydolist.size = val;
                this.getDoList();
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.querydolist.page = val;
                this.getDoList();
            },
            handleEdit(row){
                this.dohomeworkform = row;
                this.dialogFormVisible = true;
            },
            handleCreate(){
                this.dohomeworkform = {};
                this.dialogFormVisible = true
            },
            submitForm(){
                this.axios.post('http://localhost:3312/homework/doHomeWork/',this.dohomeworkform).then((resp)=>{
                    let data = resp.data;
                    if (data.success){
                        this.dialogFormVisible = false;
                        this.dohomeworkform = {};
                        this.getDoList();
                        this.$message({
                            message:"操作成功",
                            type:'success'
                        });
                    }
                })
            },
        },
    }
</script>

<style scoped>

</style>